#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n = 1;
    // while(n++ <= 1000)
    while(cin >> n)
    {
        vector<int> arr;
        for(int i = 1; i <= n; i += 2)
        {   
            arr.push_back(i);
        }
        int j = 0;
        while(arr.size() != 1)
        {
            if(j < arr.size())
                arr.erase(arr.begin() + j);
            j += 1; // 原来+=2的，但删去一个了
            if(j > arr.size())
                j = 0;
        }
        cout << arr[0] << endl;
        // cout << n << " " << arr[0] << endl
    }
    return 0;
}